package com.xr.web.controller.miniprogram;

import com.xr.common.annotation.Log;
import com.xr.common.core.controller.BaseController;
import com.xr.common.core.domain.AjaxResult;
import com.xr.common.core.page.TableDataInfo;
import com.xr.common.enums.BusinessType;
import com.xr.common.utils.poi.ExcelUtil;
import com.xr.framework.miniprogram.service.UserTokenService;
import com.xr.miniprogram.domain.MiniProgramUser;
import com.xr.miniprogram.service.IMiniProgramUserAddressService;
import com.xr.miniprogram.service.IMiniProgramUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * description: 用户模块接口
 *
 * @author: wls
 * @date: 2023/11/9 9:37
 * @version:1.0
 */
@Api("用户模块接口")
@RestController
@RequestMapping("/mini/user")
public class MpUserController extends BaseController {
    @Resource
    private IMiniProgramUserService userService;
    @Resource
    private IMiniProgramUserAddressService userAddressService;

    @Resource
    UserTokenService userTokenService;

    /**
     * 获取全部用户
     * @param miniProgramUser
     * @return
     */
    @ApiOperation("获取用户信息列表")
    @PreAuthorize("@ss.hasPermi('mini:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam(value = "用户对象，检索用") MiniProgramUser miniProgramUser){
        startPage();
        List<MiniProgramUser> list= userService.selectMiniProgramUserList(miniProgramUser);
        return getDataTable(list);
    }

    /**
     * 根据用户Id获取信息
     * @param miniProgramUserId
     * @return
     */
    @ApiOperation("根据id获取用户")
    @PreAuthorize("@ss.hasPermi('mini:user:query')")
    @GetMapping("/{miniProgramUserId}")
    public AjaxResult getByUserId(@ApiParam(value = "用户id", required = true) @PathVariable("miniProgramUserId") Long miniProgramUserId){
        return success(userService.selectMiniProgramUserByMiniProgramUserId(miniProgramUserId));
    }

    /**
     * 导出用户列表
     */
    @ApiOperation("导出用户列表")
    @PreAuthorize("@ss.hasPermi('mini:user:export')")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniProgramUser miniProgramUser)
    {
        List<MiniProgramUser> list = userService.selectMiniProgramUserList(miniProgramUser);
        ExcelUtil<MiniProgramUser> util = new ExcelUtil<MiniProgramUser>(MiniProgramUser.class);
        util.exportExcel(response, list, "用户数据");
    }
}
